<?php

/* * *
 * 网站配置控制器
 */

class configControl extends commonControl {

    function index() {
        $db = M("config");
        $base = $db->where("type=1")->all();
        $code = $db->where("type=2")->all();
        $this->assign("sonid", C("SESSION_NAME"));
        $this->assign("cokval", $_COOKIE[C("SESSION_NAME")]);
        $this->assign("config", $base);
        $this->assign("code", $code);
        $this->display();
    }

    function update() {
        $db = M("config");
        if ($db->save($_POST['conf'])) {
            $this->success('修改成功');
        } else {
            $this->error("修改失败");
        }
    }

    function saveconfig() {
        $db = M("config");
        if ($db->save($_POST['conf']) >= 0) {
            $conf = $db->where("type=1")->field("conf_title,conf_value,conf_msg")->all();
            $str = ''; //配置文件内容
            $data = array(); //配置
            foreach ($conf as $k => $v) {
                $data[$v['conf_title']] = $v['conf_value'];
            }
            $str.="<?php \n if(!defined('PATH_HD'))exit;\n return ";
            $str.=var_export($data, true);
            $str.=";\n?>";
            file_put_contents("./config/base.php", $str);
            $this->success('修改成功');
        } else {
            $this->error("修改失败");
        }
    }

    //上传水印图片
    function uploads() {
        c("debug", 0);
        c("THUMB_ON",0);
        $upload = new upload();
        $file = $upload->upload();
        if ($upload) {
            $data = array("msg" => "success", "file" => $file[0]['path']);
        } else {
            $data = array("msg" => "error");
        }
        echo json_encode($data);
    }

}

?>
